﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class EmployeesSalary_EmpSalarySummary : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SelUser.SelUserInti("", "");
            SelUser.IsAllEmp = true;
            start.Text = DateTime.Now.Year.ToString() + "-1";
            end.Text = DateTime.Now.ToString("yyyy-M");

            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "";
            master.PageName = "薪资汇总(按分类)";
            master.PicUrl = "";
            master.IntiBar();
        }
    }

    private void wgvBind(DataTable dt)
    {


        if (wgvMaster.Columns.Count > 0)
        {
            wgvMaster.Columns.Clear();
        }
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            string[] FieldId = dt.Columns[i].ToString().Split('|');

            BoundField field = new BoundField();
            field.DataField = dt.Columns[i].ToString();
            field.HeaderText = FieldId[1].ToString();
            field.DataFormatString = "{0:##0.00}";

            wgvMaster.Columns.Add(field);


        }
        wgvMaster.DataSource = dt;
        wgvMaster.DataBind();

    }
    protected void Search_Click(object sender, EventArgs e)
    {
        string mode = ddlSelType.SelectedValue;
        if (Depart.SelectDepmanetId == "0" && mode == "name" && SelUser.EmployeeId == "")
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('按人名汇总，未选择人员\\r防止产生大量数据，请选择某一部门')", true);
            return;
        }

        string st = start.Text;
        string et = end.Text;
        string id = SelUser.EmployeeId;
        string dpt = Depart.SelectDepmanetId;
        string framework = wddlFramework.SelectedValue == "-1" ? "" : wddlFramework.SelectedValue;
        object[] ret = Srvtools.CliUtils.CallMethod("SEmployees", "EmpSalarySummary", new object[] { mode, st, et, id, dpt, framework });
        wgvBind(((DataSet)ret[1]).Tables[0]);
    }

    protected void wddlFramework_DataBound(object sender, EventArgs e)
    {
        wddlFramework.Items.Remove(new ListItem("——全部——", "-1"));

        wddlFramework.Items.Add(new ListItem("——全部——", "-1"));

        wddlFramework.SelectedValue = "-1";
    }
    protected void remove_Click(object sender, EventArgs e)
    {
        SelUser.EmpName = "";

        SelUser.EmployeeId = "";
    }

    protected void wgvMaster_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        wgvMaster.PageIndex = e.NewPageIndex;
        string mode = ddlSelType.SelectedValue;
        string st = start.Text;
        string et = end.Text;
        string id = SelUser.EmployeeId;
        string dpt = Depart.SelectDepmanetId;
        string framework = wddlFramework.SelectedValue == "-1" ? "" : wddlFramework.SelectedValue;
        object[] ret = Srvtools.CliUtils.CallMethod("SEmployees", "EmpSalarySummary", new object[] { mode, st, et, id, dpt, framework });
        wgvBind(((DataSet)ret[1]).Tables[0]);
    }
}
